package com.example.app.controller;

import com.example.app.config.LoginUser;
import com.example.app.entity.Conversation;
import com.example.app.service.ConversationService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ConversationController {
    @Resource
    private ConversationService conversationService;

    @GetMapping("/conversations")
    public ResponseEntity<List<Conversation>> getConversations() {
        LoginUser principal = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<Conversation> conversations = conversationService.getRecentConversations(principal.getUserId());

        return ResponseEntity.ok(conversations);
    }
}
